package com.example.kotlinview.room

import androidx.room.*

@Dao
interface UserDao {
//    onConflict = OnConflictStrategy.REPLACE
//    优化插入，解决重复插入同一对象崩溃问题
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertUser(user:User):Long

    @Update
    fun updateUser(newUser:User)

    @Query("select * from User")
    fun loadAllUsers():List<User>

    @Delete
    fun deleteUser(user :User)

    @Query("delete from User where lastName = :lastName")
    fun deleteUserByLastName(lastName:String):Int

}